home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ILINES.ZIP / XLINES2.CPP next >
Encoding:
C/C++ Source or Header  |  1996-01-06  |  1.6 KB  |  71 lines

  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. //Returns 1 if they intersect
  5. //returns 0 otherwise
  6. short LinesIntersect(unsigned long x1,unsigned long y1,
  7.                      unsigned long x2,unsigned long y2,
  8.                      unsigned long x3,unsigned long y3,
  9.                      unsigned long x4,unsigned long y4)
  10. {
  11.     unsigned long d;
  12.     d = (((y2-y1)*(x3-x4))-((y4-y3)*(x1-x2)));
  13.     if (!d)
  14.     {
  15.         return 0;
  16.     }
  17.     else
  18.     {
  19.         return 1;
  20.     }
  21. }
  22.  
  23.  
  24. short main()
  25. {
  26.     long x1,x2,x3,x4,y1,y2,y3,y4;
  27.     long index;
  28.     clock_t st,et;
  29.     long tt;
  30.     float tps;
  31.     
  32.     printf("X1, Y1: ");
  33.     scanf( "%ld %ld", &x1, &y1 );
  34.     printf( "X2, Y2: " );
  35.     scanf( "%ld %ld", &x2, &y2 );
  36.     printf( "X3, Y3: " );
  37.     scanf( "%ld %ld", &x3, &y3 );
  38.     printf( "X4, Y4: " );
  39.     scanf( "%ld %ld", &x4, &y4 );
  40.  
  41.     if (!LinesIntersect(x1,y1,x2,y2,x3,y3,x4,y4))
  42.     {
  43.         printf("Lines don't intersect\n");
  44.     }
  45.     else
  46.     {
  47.         printf("Lines intersect\n");// at %f,%f\n",intersectx,intersecty);
  48.     }
  49.     printf("Testing 500000 Times!\n");
  50.     st=clock();
  51.     for (index=0; index<500000; index++)
  52.     {
  53.         //LinesIntersect(x1,y1,x2,y2,x3,y3,x4,y4);
  54.         unsigned long d;
  55.         d = (((y2-y1)*(x3-x4))-((y4-y3)*(x1-x2)));
  56.         if (!d)
  57.         {
  58.             //return 0;
  59.         }
  60.         else
  61.         {
  62.             //return 1;
  63.         }
  64.     }
  65.     et=clock();
  66.     tt=(long)et-(long)st;
  67.     tps=((float)500000/(float)tt)*(float)CLK_TCK;
  68.     printf("Total Test Per Second:%f\n",tps);
  69.     return 0;
  70. }
  71.